/**
 * Plugin twitter para RainFox
 * 
 * @author Javier Pérez <javier@javierperez.eu>
 * @license GPL
 * @version 1.0
 */
oRainFox.drivers.push({
	title:		"twitter",
	home:		"http://twitter.com/",
	icon:		'http://twitter.com/favicon.ico',

	location:	'http://search.twitter.com/search?q={WORD+}',
	query:		'',
	method:		'get',

	driver:		function rf_p_twitter(o,doc) {
		// Array de gotas
		var drops = [];

		var lis = RF_DOM.classeds(o, 'li', 'result');
		for (var i=0; i<lis.length; i++) {
			var avatar = RF_DOM.classeds(lis[i], 'div', 'avatar')[0];
			var msg = RF_DOM.classeds(lis[i], 'div', 'msg')[0];
			var info = RF_DOM.classeds(lis[i], 'div', 'info')[0];
			var url = null;
			
			// obtenemos el enlace al tweet
			var as = RF_DOM.classeds(lis[i], 'a', 'lit');
			for (var x=0; x<as.length; x++) {
				dump('twitter: ' + as[x].href + ' ');
				if ((as[x].href+'').match(/statuses/) != null) {
					url = as[x].href;
					dump('matched!\n');
					break;
				} else {
					dump('not match!\n');
				}
			}
			
			// Eliminamos "expand"
			var expand = RF_DOM.classeds(msg, 'span', 'expand')[0];
			if (expand) expand.innerHTML = '';
			
			// Colocamos avatar y msg
			var html = '<div style="float:left; overflow:hidden; width:48px; height:48px;">' + avatar.innerHTML + '</div>';
			html += '<div style="margin-left:58px; ">' + msg.innerHTML + '</div>';
			
			drops.push({
				href:	url,
				html:	html
			});
		}
		
		// Se devuelven las gotas
		return drops;
	}
});
